<template>
    <textarea class="textarea" v-model="routerStr"></textarea>
</template>

<script setup>
import { reactive,ref,getCurrentInstance,toRefs,toRaw } from 'vue'
let { proxy } = getCurrentInstance()
let routerStr = ref("")

proxy.$ajax({
    url: 'menu',
    data: {},
    bfLoading: true
}).then(d => {
    let routerAry = ""
    d.msg.forEach(m => {
        //以下是用来生成后台菜单的
        m.sub.forEach(t =>{
            let root = `
        {
            path: "/${t.component}",
            component: () => import('../pages/${t.sub.length>0 ? `${t.component}/list.vue` : `${t.component}.vue`}'),
            meta: { title: "${t.label}" },${t.sub.length>0 ? `
            children: [${t.sub.map(t2 => {
                return `
                {
                    path: "${t2.component=="edit" ? "" : t2.component}",
                    component: () => import('../pages/${t.component}/${t2.component}.vue'),
                    meta: { title: "${t2.label}" }
                }`
            })}
            ]`: ``}
        },`
            // routerAry.push(root)
            routerAry += root
        })
    })
    routerStr.value = `const mainChildren = [${routerAry}
    ]

    export default mainChildren`
}).catch(e => {
    console.log(e)
    if(e == "登录已过期，请重新登录")
        proxy.routerPushMixin('/')
})

// let { routerStr } = toRefs(obj)
</script>

<style lang="scss" scoped>
.textarea {width: 100vw; height: 100vh;}
</style>